package com.ciba.demo.controller;

import com.ciba.demo.respone.ApiRestResponse;
import com.ciba.demo.service.LoginService;
import com.ciba.demo.service.RegisterService;
import com.ciba.demo.service.PlanService;
import com.ciba.demo.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class UserController {

    @Autowired
    RegisterService registerService ;

    @Autowired
    UserInfoService userInfoService ;

    @Autowired
    LoginService loginService ;

    @PostMapping("/getRegisterCode")
    @ResponseBody
    ApiRestResponse getRegisterCode(HttpServletRequest request, HttpServletResponse response){
        return registerService.getCode(request,response) ;
    }

    @PostMapping("/register")
    @ResponseBody
    ApiRestResponse register(HttpServletRequest request, HttpServletResponse response){
        return registerService.register(request,response) ;
    }

    @PostMapping("checkAccount")
    @ResponseBody
    ApiRestResponse checkAccount(HttpServletRequest request, HttpServletResponse response){
        return loginService.checkAccount(request,response) ;
    }

    @PostMapping("/login")
    @ResponseBody
    ApiRestResponse login(HttpServletRequest request,HttpServletResponse response){
        System.out.println(request.getSession().getId());
        return  loginService.checkUser(request,response) ;
    }

    @GetMapping("/getUserInfo")
    @ResponseBody
    ApiRestResponse getUserInfo(HttpServletRequest request , HttpServletResponse response){
        return  userInfoService.getUserInfo(request,response) ;
    }

    @PostMapping("/changUserInfo")
    @ResponseBody
    ApiRestResponse changUserInfo(HttpServletRequest request ,HttpServletResponse response){
        return userInfoService.changeUserInfo(request,response) ;
    }

}
